package com.shengruan.admin.jdbc;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.shengruan.admin.vo.Content;
import com.shengruan.framework.jdbc.BaseJdbc;
import com.shengruan.framework.jdbc.BeanHandler;

public class ContentJdbc  extends BaseJdbc{
	protected static Log log = LogFactory.getLog(ContentJdbc.class);
	/**
	 * 保存
	 */
	public void save(Content content)
	{

		Connection conn = this.getConnection();
	
		String sql = "insert into Content (" +
		"id,content)" +
		" values(?,?)";
		try {
			this.execute(conn, sql,content.getId(),content.getContent());
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			this.close(conn);
		}
	}
	
	/**
	 * 更新
	 */
	public void update(Content content)
	{
		Connection conn = this.getConnection();
	
		String sql = "update Content set " +
		"content=?" +
		" where id=?";
		
		try {
			
			this.execute(conn, sql,content.getContent(),content.getId());
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			this.close(conn);
		}
	}
	
	
	/***
	 * 根据用ID获得
	 */
	public Content getById(int id)
	{
		Connection conn = this.getConnection();
		Content content =null;
		String sql = "select * from Content where id = ?";

		try {
			content = this.query(conn, sql, new BeanHandler<Content>(Content.class),id);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			this.close(conn);
		}
		return content;
	}
	
}
